package myactor

import akka.actor.{Actor, ActorSystem, Props}
import com.typesafe.config.ConfigFactory

class MyNodeManager extends  Actor{

  def doHi():Unit={
    println("MyNodeManager ; 接收到 MyResourceManager 的  Hi 消息")
  }

  override def preStart(): Unit ={

    val rmref = context.actorSelection("akka.tcp://MyResourceManagerActorSystem@localhost:19888/user/MyResourceManagerActor")
    rmref ! "Hello"
  }

  override def receive: Receive = {
    case "Hi" =>{
      doHi()
    }
  }
}

object MyNodeManager {
  def main(args: Array[String]): Unit = {
    val str=
      """
        |akka.actor.provider = "akka.remote.RemoteActorRefProvider"
        |akka.remote.netty.tcp.hostname = localhost
      """.stripMargin

    val config = ConfigFactory.parseString(str)
    val actorSystem = ActorSystem("MyNodeManagerActorSystem", config)
    actorSystem.actorOf(Props(new MyNodeManager()), "MyNodeManagerActor")
  }
}
